import { Component } from '@angular/core';
import { Platform } from 'ionic-angular';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';

import { TabsPage } from '../system/pages/tabs/tabs';
import { LoginPage } from "../system/pages/login/login";
import {AppGlobal} from "../system/services/app.service";
import {Storage} from "@ionic/storage";
import {AppInitService} from "../system/services/appInit.service";

@Component({
  templateUrl: 'app.html'
})
export class MyApp {
  rootPage:any;

  constructor(platform: Platform,
              statusBar: StatusBar,
              splashScreen: SplashScreen,
              appInitService:AppInitService,
              storage:Storage
              ) {

    //判断缓存中token是否存在，若存在直接跳转首页，否则跳转登录页
    storage.get("token").then(value => {
      if(value!=null){//不为空
        this.rootPage=TabsPage;
        AppGlobal.token = value;
      } else {//为空
        this.rootPage=LoginPage;
      }
    })

    platform.ready().then(() => {
      // Okay, so the platform is ready and our plugins are available.
      // Here you can do any higher level native things you might need.
      statusBar.styleDefault();
      splashScreen.hide();
      //初始化
      appInitService.init();


    });
  }
}
